import {AABB, Sphere} from "../geometry";
import {IOriginNormalVertexData, IOriginVertexData, IOriginWireFrameData} from "./originDtata";

// 线框数据
export interface IWireFrameData {
    positions: Float32Array,
    indices: Uint16Array
}

class WireFrameData implements IWireFrameData {
    public constructor(public positions: Float32Array, public indices: Uint16Array) {
    }
}

export interface INormalVertexData {
    positions: Float32Array,
}

class NormalVertexData implements INormalVertexData {
    public constructor(public positions: Float32Array) {
    }
}

export interface IVertexData {
    positions: Float32Array,
    normals: Float32Array,
    texCoords: Float32Array,
    indices: Uint16Array,
}

class VertexData implements IVertexData {
    public constructor(
        public positions: Float32Array,
        public normals: Float32Array,
        public texCoords: Float32Array,
        public indices: Uint16Array,
    ) {
    }
}

export interface IMeshData {
    vertexData: IVertexData,
    wireFrameData: IWireFrameData | null,
    normalVertexData: INormalVertexData | null,
    aabb: AABB,
    sphere: Sphere,
}

export class MeshData implements IMeshData {

    vertexData: IVertexData;
    wireFrameData: IWireFrameData;
    normalVertexData: INormalVertexData;

    public constructor(originVertexData: IOriginVertexData,
                       originWireFrameData: IOriginWireFrameData,
                       originNormalVertexData: IOriginNormalVertexData,
                       public sphere: Sphere,
                       public aabb: AABB
    ) {

        // 主要的数据
        this.vertexData = new VertexData(
            new Float32Array(originVertexData.positions),
            new Float32Array(originVertexData.normals),
            new Float32Array(originVertexData.texCoords),
            new Uint16Array(originVertexData.indices)
        );

        // 线框数据
        this.wireFrameData = new WireFrameData(
            this.vertexData.positions,
            new Uint16Array(originWireFrameData.indices)
        );

        // 法线数据
        this.normalVertexData = new NormalVertexData(
            new Float32Array(originNormalVertexData.positions)
        );
    }

    // positions:Float32Array[];
    // indices:Uint16Array[];
    // normals:Float32Array[];
    // texCoords:Float32Array[];
    // boundingSphere:Sphere;

    /**
     *
     * @param output
     * {
     *      positions:[]
     *      indices:[],
     *      normals:[],
     *      texCoords:[],
     *      sphere: {},
     *      wireFrame:{
     *          positions:positions,
     *          indices:[]
     *      },
     *      norm:{
     *          positions:[]
     *      },
     *      aabb:{
     *          positions:[],
     *          indices:[]
     *      }
     * }
     */
    // constructor(output) {
    //
    //     // 主要的数据
    //     this.positions = new Float32Array(output.positions);
    //     this.indices = new Uint16Array(output.indices);
    //     this.normals = new Float32Array(output.normals);
    //     this.texCoords = new Float32Array(output.texCoords);
    //     this.sphere = {
    //         radius:output.sphere.radius,
    //         center:output.sphere.center,
    //     };
    //
    //     // 线框
    //     this.wireFrame = {};
    //     this.wireFrame.positions = this.positions;
    //     this.wireFrame.indices = new Uint16Array(output.wireFrame.indices);
    //
    //     // 法线
    //     this.norm = {};
    //     this.norm.positions = new Float32Array(output.norm.positions);
    //
    //     // aabb
    //     this.aabb = {};
    //     this.aabb.position = new Float32Array(output.aabb.positions);
    //     this.aabb.indices = new Uint16Array(output.aabb.indices);
    // }
}

